!     Copyright (C) 2010 Benjamin Piaud
!
!     LIMBES is free software; you can redistribute it and/or modify
!     it under the terms of the GNU General Public License as published by
!     the Free Software Foundation; either version 3, or (at your option)
!     any later version.

!     LIMBES is distributed in the hope that it will be useful,
!     but WITHOUT ANY WARRANTY; without even the implied warranty of
!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!     GNU General Public License for more details.

!     You should have received a copy of the GNU General Public License
!     along with LIMBES; if not, see <http://www.gnu.org/licenses/>


!     this include contains declaration of fluid parameters and flow configuration
!     fluid parameters begin by FLUID_
!     flow configuration parameter begin by SIMUL_ (like simulation)
!     reference temperature multiply massique fluid constant

module LIMBES_mod_fluid_config
  implicit none
  real*8 ::FLUID_RT0,FLUID_R

  !     Quadrature
  integer*8 SIMUL_Nquad

  !     domain size
  integer*8 ::SIMUL_nx,SIMUL_ny,SIMUL_cell_number,SIMUL_step_number
  integer*8 ::VTK_xmin,VTK_xmax,VTK_ymin,VTK_ymax
  real*8 ::SIMUL_Lx,SIMUL_Ly,SIMUL_dx,SIMUL_dt,SIMUL_dttau
  character*50 ::SIMUL_path

  !     gravity
  real*8 ::SIMUL_gx,SIMUL_gy

  !     collision time tau
  real*8 ::FLUID_tau
  character*50 ::FLUID_tau_expr

  !     thermal/isothermal choice
  character*50 ::SIMUL_thermal

  !     number of time to save
  integer*8 ::SIMUL_save_number

  !     variables concerning boundary
  character*50 SIMUL_boundary
  character*2, allocatable :: SIMUL_1wall_boundary_type(:)
  character*2, allocatable :: SIMUL_2wall_boundary_type(:,:)
  integer*8 :: SIMUL_1wall_cell_number,SIMUL_2wall_cell_number
  integer*8, allocatable :: SIMUL_1wall_cell(:), SIMUL_2wall_cell(:)
  integer*8, allocatable :: SIMUL_1wall_RLUD(:,:)
  integer*8, allocatable :: SIMUL_2wall_RLUD(:,:)
  real*8, allocatable :: SIMUL_1wall_alpha(:,:)
  real*8, allocatable :: SIMUL_2wall_alpha1(:,:)
  real*8, allocatable :: SIMUL_2wall_alpha2(:,:)

  !     declaration of miscellaneous constants
  real*8 :: zero,one,two,three,pi
  parameter(zero=0.0d+0,one=1.0d+0,two=2.0d+0,three=3.0D+0)

contains
  subroutine init_LIMBES_fluid_config(ncell1,ncell2)
    implicit none
    integer*8 :: ncell1,ncell2,izero
    real*8 :: zero
    parameter(zero=0.0D+0,izero=0)
    allocate(SIMUL_1wall_boundary_type(1:ncell1))
    SIMUL_1wall_boundary_type='O'
    allocate(SIMUL_2wall_boundary_type(1:ncell2,1:2))
    SIMUL_2wall_boundary_type='O'
    allocate(SIMUL_1wall_cell(1:ncell1))
    SIMUL_1wall_cell=izero
    allocate(SIMUL_2wall_cell(1:ncell2))
    SIMUL_2wall_cell=izero
    allocate(SIMUL_1wall_RLUD(1:ncell1,1:4))
    SIMUL_1wall_RLUD=izero
    allocate(SIMUL_2wall_RLUD(1:ncell2,1:4))
    SIMUL_2wall_RLUD=izero
    allocate(SIMUL_1wall_alpha(1:ncell1,1:4))
    SIMUL_1wall_alpha=zero
    allocate(SIMUL_2wall_alpha1(1:ncell2,1:4))
    SIMUL_2wall_alpha1=zero
    allocate(SIMUL_2wall_alpha2(1:ncell2,1:4))
    SIMUL_2wall_alpha2=zero
  end subroutine init_LIMBES_fluid_config

  subroutine free_LIMBES_fluid_config()
    implicit none
    deallocate(SIMUL_1wall_boundary_type)
    deallocate(SIMUL_2wall_boundary_type)
    deallocate(SIMUL_1wall_cell)
    deallocate(SIMUL_2wall_cell)
    deallocate(SIMUL_1wall_RLUD)
    deallocate(SIMUL_2wall_RLUD)
    deallocate(SIMUL_1wall_alpha)
    deallocate(SIMUL_2wall_alpha1)
    deallocate(SIMUL_2wall_alpha2)
  end subroutine free_LIMBES_fluid_config

  subroutine check_init_LIMBES_fluid_config()
    implicit none
    if (.NOT.allocated(SIMUL_1wall_boundary_type)) print*,'SIMUL_1wall_boundary_type not allocated'
    if (.NOT.allocated(SIMUL_2wall_boundary_type)) print*,'SIMUL_2wall_boundary_type not allocated'
    if (.NOT.allocated(SIMUL_1wall_cell)) print*,'SIMUL_1wall_cell not allocated'
    if (.NOT.allocated(SIMUL_2wall_cell)) print*,'SIMUL_2wall_cell not allocated'
    if (.NOT.allocated(SIMUL_1wall_RLUD)) print*,'SIMUL_1wall_RLUD not allocated'
    if (.NOT.allocated(SIMUL_2wall_RLUD)) print*,'SIMUL_2wall_RLUD not allocated'
    if (.NOT.allocated(SIMUL_1wall_alpha)) print*,'SIMUL_1wall_alpha not allocated'
    if (.NOT.allocated(SIMUL_2wall_alpha1)) print*,'SIMUL_2wall_alpha1 not allocated'
    if (.NOT.allocated(SIMUL_2wall_alpha2)) print*,'SIMUL_2wall_alpha2 not allocated'
  end subroutine check_init_LIMBES_fluid_config

end module LIMBES_mod_fluid_config
